package thread;

import java.util.Scanner;

public class Demo25 {
    public static void main(String[] args) {
        Object object = new Object();

        Thread t1 = new Thread(() -> {
            try{
                System.out.println("t1 wait 之前");
                synchronized (object) {
                    object.wait();
                }
                System.out.println("t1 wait 之后");
            }catch (InterruptedException e){
                throw new RuntimeException();
            }
        });

        Thread t2 = new Thread(() -> {
            try{
                System.out.println("t2 wait 之前");
                synchronized (object) {
                    object.wait(3000);
                }
                System.out.println("t2 wait 之后");
            }catch (InterruptedException e){
                throw new RuntimeException();
            }
        });

        Thread t3 = new Thread(() -> {
            Scanner in = new Scanner(System.in);
            System.out.println("输入任意内容唤醒线程");
            in.next();
            synchronized (object) {
                //object.notify();
                object.notifyAll();
            }

        });

        t1.start();
        t2.start();
        t3.start();
    }
}
